<?php
/**
 * Created by PhpStorm.
 * User: xuewl
 * Date: 2017/12/25
 * Time: 09:34
 */

namespace app\message\service;
use app\common\library\Service;

class Message extends Service
{
    use \app\common\library\traits\Model;

    protected $model;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('message/message');
    }

    /**
     * @param integer $to
     * @param string $title
     * @param string $content
     * @param integer $from
     * @param array $extra
     * @return boolean
     */
    public function send($to, $title, $content, $from = 0, $extra = []) {
        $info = [
            'to' => $to,
            'title' => $title,
            'content' => $content,
            'from' => $from,
        ];
        if($extra) $info = array_merge($info, $extra);
        $result = $this->model->create($info);
        if(!$result) {
            $this->error = $this->getError();
            return false;
        }
        return $result;
    }

}